﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using digit.Core;
using SMS.ServiceManager;
using SMS.UserManager;
using digit.Security;

public partial class Modules_CheckMsg : WebControlBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ClientState.MemberInfo.UserType == 0 || ClientState.MemberInfo.UserType == 1 || ClientState.MemberInfo.UserType == 5)
        {
            this.txtFromDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
            this.txtToDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
            this.txtContent.Text = "";
        }
        else
            Response.Redirect("Default.aspx?module=Warning");
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            this.grvSms.DataSource = this.BuildData(this.ddlServicID.SelectedValue, this.txtContent.Text, Convert.ToDateTime(this.txtFromDate.Text), Convert.ToDateTime(this.txtToDate.Text));
            this.grvSms.DataBind();
        }
        catch (Exception ex) { this.lblError.Text = ex.ToString(); }
    }

    private DataTable BuildData(string ServiceID, string MsgContent, DateTime FromDate, DateTime ToDate)
    {
        DataTable dt = null;

        if (ddlMsgType.SelectedValue.ToLower() == "mo")
            dt = MessageInManager.SearchMsgIn_ByServiceID_Online(ServiceID, MsgContent, FromDate, ToDate);

        else
            dt = MessageOutManager.SearchMsgOut_ByServiceID_Online(ServiceID, MsgContent, FromDate, ToDate);

        if (dt != null && dt.Rows.Count > 0)
        {
            return dt;
        }
        else
        {
            this.lblError.Text = "Hiện tại chưa có số liệu bạn cần tìm.";
        }
        return null;
    }
}
